package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.RoleDto;
import com.zzyl.service.RoleService;
import com.zzyl.vo.RoleVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/role")
@Api(tags = "角色管理")
public class RoleControlelr {

    @Autowired
    private RoleService roleService;

    @PostMapping("/page/{pageNum}/{pageSize}")
    @ApiOperation("角色分页")
    public ResponseResult<PageResponse<List<RoleVo>>> list(@RequestBody RoleDto roleDto,
                                                          @PathVariable Integer pageNum,
                                                          @PathVariable Integer pageSize){
        PageResponse<RoleVo> pageResponse = roleService.queryPage(roleDto,pageNum, pageSize);
        return ResponseResult.success(pageResponse);
    }

    @PutMapping
    @ApiOperation("角色添加")
    public ResponseResult insert(@RequestBody RoleDto roleDto){
        roleService.insert(roleDto);
        return ResponseResult.success();
    }

    @GetMapping("/find-checked-resources/{roleId}")
    @ApiOperation("根据角色id查询已选中的菜单编号")
    public ResponseResult<List<String>> findCheckedResourcesByRoleId(@PathVariable Long roleId){
        List<String> list = roleService.findCheckedResourcesByRoleId(roleId);
        return ResponseResult.success(list);
    }

    @PatchMapping
    @ApiOperation("角色修改+禁用+菜单编辑公用接口")
    public ResponseResult editAndStatusAndResource(@RequestBody RoleDto roleDto){
        roleService.editAndStatusAndResource(roleDto);
        return ResponseResult.success();
    }

    @PostMapping("/init-roles")
    @ApiOperation("角色下拉框")
    public ResponseResult<List<RoleVo>> ininRoles(){
        List<RoleVo> roleVos = roleService.inintRoles();
        return ResponseResult.success(roleVos);
    }

}




















